package com.huluspace.military.service;


import com.huluspace.military.model.MilitaryEvent;
import com.huluspace.military.model.Region;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MapService {
  private final List<MilitaryEvent> data = new ArrayList<>(); // 数据


  // 添加事件
  public void addEvent(MilitaryEvent event) {
    data.add(event);
  }

  public List<MilitaryEvent> getEvents(Region region) {
    return data.stream()
        .filter(event -> {
          double lat = event.getLatitude();
          double lng = event.getLongitude();
          return lat >= region.getMinLatitude() && lat <= region.getMaxLatitude()
              && lng >= region.getMinLongitude() && lng <= region.getMaxLongitude();
        })
        .collect(Collectors.toList());
  }

}
